import javax.swing.*;

import java.awt.*;
import java.awt.event.*;

public class JComboBoxTest extends JFrame implements ItemListener{
	JComboBox jcb1,jcb2;
	String[] profNames1={"西安","安康","汉中","榆林"};
	String[] profNames2={"大同","吕梁","晋城"};
	public JComboBoxTest()
	{
		setSize(300,200);
		setLayout(null);
		String[] collegeNames={"陕西","山西"};
		String[] profNames1={"西安","安康","汉中","榆林"};
		String[] profNames2={"大同","吕梁","晋城"};
		jcb1=new JComboBox(collegeNames);
		jcb1.setLocation(30,30);
		jcb1.setSize(200, 30);
		jcb1.addItemListener(this);
		jcb2=new JComboBox(profNames1);
		jcb2.setLocation(30,80);
		jcb2.setSize(200, 30);
		this.add(jcb1);
		this.add(jcb2);
		setVisible(true);
	}

	@Override
	public void itemStateChanged(ItemEvent e) {
		// TODO Auto-generated method stub
		if(jcb1.getSelectedItem().toString().equals("电智学院"))
		{
			jcb2.removeAllItems();
			for(int i=0;i<profNames1.length;i++)
			{
				jcb2.addItem(profNames1[i]);
			}
		}
		else
		{
			jcb2.removeAllItems();
			for(int i=0;i<profNames2.length;i++)
			{
				jcb2.addItem(profNames2[i]);
			}
		}
	}
} 
